home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS08.ADF
/
C
/
SetWindow.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-02
|
4KB
|
108 lines
/*
Subject: ICONEXEC utility
Date-Received: 22 Feb 86 06:37:26 GMT
Sender: jcz@ncsu.UUCP
Organization: SAS Institute Inc.
Lines: 256
Here are two simple utilities that may make it easier to write code that
runs from workbench. The second utility IconExec allows you to run any
arbitrary command from an Icon WITHOUT having to recompile a program
everytime you wish to change what is run. The other utility allows you
to set the default window that will be used when an Icon is selected.
As a matter of short explaination, whenever an Icon is selected, the
ToolWindow field is (supposed to be) copied into the initial startup
message that is passed to your program. The startup code (c.o) looks
at that message and opens up that window by default. In this way you can
always associate a window with a program without having to open it in
your code. Unfortunately, Intuition (or whomever is responsible) fails
to copy the ToolWindow field over and no window is opened currently.
ICONEXEC takes that into account and opens up the window anyway (Until
the parameter gets copied correctly in a later OS release) and sets it
as the default window.
Once a window is established, the commands that are contained in the
ToolTypes arrays are then executed one at a time. More detailed information
about how the Icons are organizied is in Chapter 4 of Volume1 in the 1.1
Rom Kernal Manual, although the information is not critical to using
the program. If enough interest exists, I will create a tutorial on
using Icons or whatever other information is desired in creating/accessing
them from a program.
These programs were created in response to a request for being able to run
programs such as MUSICRAFT which have no ICONS without Having to modify
the program. If you plan on using ICONEXEC for a commercial product, just
contact me first.
-----cut here for SetWindow.c------------
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* SetWindow - Set the ToolWindow for an ICON */
/* (c) Copyright 1986 John A. Toebes, VIII All rights reserved */
/* 120-H Northington Place, Cary NC 27511 (919) 469-4210 */
/* This program may be used and modified for any purpose so long as */
/* this copyright notice remains with the code and the program is not */
/* sold and no charge is made for its use. */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* To use:
1) Compile and link as any other program
2) Issue command to modify whatever Icon you wish to
SetWindow <icon> <window specifications>
*/
#include <stdio.h>
#include <exec/types.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>
#include <workbench/startup.h>
int IconBase;
extern struct WBStartup *WBenchMsg;
main(argc,argv)
int argc;
char *argv[];
{
struct DiskObject *diskobj, *GetDiskObject();
char *savewindow;
/* make sure we ran from CLI */
if (argc == 0) exit(1);
/* make sure we have enough parms */
if (argc != 2 && argc != 3)
{
printf("Usage: %s <icon> [<windowspec>]\n", argv[0]);
exit(2);
}
if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
exit(2);
/* get the icon from disk */
if ( (diskobj = GetDiskObject(argv[1])) == NULL)
{
printf("Cannot read icon for %s\n", argv[1]);
CloseLibrary( IconBase );
exit(3);
}
/* remember what the previous window was */
savewindow = diskobj->do_ToolWindow;
/* set it to what was requested */
diskobj->do_ToolWindow = (argc > 2) ? argv[2] : NULL;
/* write the corrected ICON to disk */
if (!PutDiskObject( argv[1], diskobj))
printf("Cannot write new icon - code %d\n", IoErr() );
/* restore the oldwindow and free the object */
diskobj->do_ToolWindow = savewindow;
FreeDiskObject( diskobj );
CloseLibrary( IconBase );
}
/* -----end of SetWindow.c------------- */